package com.cmcc.aregister.ui.activity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;

import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.cmcc.aregister.R;
import com.cmcc.aregister.cs.constant.Arguments;
import com.cmcc.aregister.cs.constant.ConfigUtilHelper;
import com.cmcc.aregister.cs.constant.GlobalSetting;
import com.cmcc.aregister.cs.http.HttpAsyncTask;
import com.cmcc.aregister.cs.model.Department;
import com.cmcc.aregister.cs.model.Doctor;
import com.cmcc.aregister.cs.model.Hospital;
import com.cmcc.aregister.cs.util.PotoalParcelable;
import com.cmcc.aregister.cs.util.Utils;
import com.cmcc.aregister.ui.adapter.DepartmentAdapter;
import com.cmcc.aregister.ui.adapter.DoctorAdapter;
import com.cmcc.aregister.ui.adapter.HospitalAdapter;
import com.cmcc.sdk.CmccDataStatistics;

/**
 * 名医名院页面
 */
public class HospitalActivity extends ParentActivity
{
    private static final String TAG = "HospitalActivity";
    // ------view------
    private Button top_left_image;
    private Button top_right_btn;
    private Button top_search_btn;
    private TextView top_left;
    private TextView top_center;
    private TextView top_right;
    private ImageView search_btn;
    private ListView listView;
    private LinearLayout no_data_layout, three_head_layout, search_layout;
    private EditText search_edittext;
    // ------parameter------
    private List<Hospital> hospitalList = new ArrayList<Hospital>();
    private List<Doctor> doctorList = new ArrayList<Doctor>();
    private List<Department> departmentList = new ArrayList<Department>();
    private int currentTitleSelect = -1;
    private int currPage = 0;
    private int allPage = 0;

    // ------view------
    private HospitalAdapter hospitalAdapter;
    private DepartmentAdapter departmentAdapter;
    private DoctorAdapter doctorAdapter;

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        init(R.layout.p_hospital);
        mHttpManager.setCxt(getParent());
    }

    /**
     * 默认获取本地医院列表
     */
    @Override
    protected void setupData()
    {
        sendGetHospitalListTask("0", ConfigUtilHelper.getMobile(app), "", "",
            "1", HttpAsyncTask.CACHE_TYPE_SAVE);
    }

    @Override
    protected void setupView()
    {
        ((ImageView) findViewById(R.id.title))
            .setBackgroundResource(R.drawable.minyiminyuan);
        top_left_image = (Button) findViewById(R.id.top_left_image);
        top_right_btn = (Button) findViewById(R.id.top_right_btn);
        top_search_btn = (Button) findViewById(R.id.top_search_btn);
        search_btn = (ImageView) findViewById(R.id.search_btn);
        top_search_btn.setOnClickListener(onClickListener);
        search_btn.setOnClickListener(onClickListener);
        top_left = (TextView) findViewById(R.id.left_btn);
        top_center = (TextView) findViewById(R.id.center_btn);
        top_right = (TextView) findViewById(R.id.right_btn);
        listView = (ListView) findViewById(R.id.listview);
        no_data_layout = (LinearLayout) findViewById(R.id.no_data_layout);
        three_head_layout = (LinearLayout) findViewById(R.id.three_top_header);
        search_layout = (LinearLayout) findViewById(R.id.search_layout);
        top_left_image.setVisibility(View.VISIBLE);
        top_right_btn.setVisibility(View.VISIBLE);
        top_left_image.setOnClickListener(onClickListener);
        top_right_btn.setOnClickListener(onClickListener);
        top_left.setOnClickListener(onClickListener);
        top_center.setOnClickListener(onClickListener);
        top_right.setOnClickListener(onClickListener);
        listView.setOnItemClickListener(onItemClickListener);
        search_edittext = (EditText) findViewById(R.id.search_content);
        check(R.id.left_btn, false);
    }

    OnItemClickListener onItemClickListener = new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int position,
            long arg3)
        {
            Intent intent = null;
            Map<String, Object> httpMap = new HashMap<String, Object>();
            PotoalParcelable potoal = new PotoalParcelable(httpMap);
            switch (currentTitleSelect)
            {
            case R.id.left_btn:
                intent = new Intent(HospitalActivity.this,
                    HospitalDetailActivity.class);
                httpMap.put(Arguments.ACTIVITY_JUMP_HOSPITAL,
                    hospitalList.get(position));
                httpMap.put(Arguments.ACTIVITY_JUMP_AREA_TYPE,
                    hospitalList.get(position).area_type);
                break;
            case R.id.center_btn:
                intent = new Intent(HospitalActivity.this,
                    DepartmentDetailActivity.class);
                httpMap.put(Arguments.ACTIVITY_JUMP_DEPARTMENT,
                    departmentList.get(position));// 传入的是从科室列表里的一个科室对象，本身就包含医院名称（unit_name）
                httpMap.put(Arguments.ACTIVITY_JUMP_AREA_TYPE,
                    departmentList.get(position).area_type);
                break;
            case R.id.right_btn:
                intent = new Intent(HospitalActivity.this,
                    DoctorDetailActivity.class);
                httpMap.put(Arguments.ACTIVITY_JUMP_DOCTOR,
                    doctorList.get(position));
                httpMap.put(Arguments.ACTIVITY_JUMP_AREA_TYPE,
                    doctorList.get(position).area_type);
                break;
            }
            httpMap.put(Arguments.ACTIVITY_JUMP_POSITION, position);
            intent.putExtra(Arguments.INTENT_TO_NEXT_PAGE, potoal);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
        }
    };

    OnClickListener onClickListener = new OnClickListener() {
        @Override
        public void onClick(View v)
        {
            int id = v.getId();
            if (id == R.id.top_right_btn)
            {
                Intent intent = new Intent(HospitalActivity.this,
                    ScreeningActivity.class);
                Map<String, Object> httpMap = new HashMap<String, Object>();
                switch (currentTitleSelect)
                {
                case R.id.left_btn:
                    top_search_btn.setVisibility(View.VISIBLE);
                    top_left
                        .setBackgroundResource(R.drawable.by_hospital_press);
                    top_center.setBackgroundResource(R.drawable.by_dept);
                    top_right.setBackgroundResource(R.drawable.by_all_doctor);
                    CmccDataStatistics.onEvent(HospitalActivity.this, 0,
                        "f_hos");
                    httpMap.put(Arguments.ACTIVITY_JUMP_SCREENING_TYPE, 0);
                    break;
                case R.id.center_btn:
                    top_left.setBackgroundResource(R.drawable.by_hospital);
                    top_center.setBackgroundResource(R.drawable.by_dept_press);
                    top_right.setBackgroundResource(R.drawable.by_all_doctor);
                    CmccDataStatistics.onEvent(HospitalActivity.this, 0,
                        "f_dep");
                    httpMap.put(Arguments.ACTIVITY_JUMP_SCREENING_TYPE, 1);
                    break;
                case R.id.right_btn:
                    top_left.setBackgroundResource(R.drawable.by_hospital);
                    top_center.setBackgroundResource(R.drawable.by_dept);
                    top_right
                        .setBackgroundResource(R.drawable.by_all_doctor_press);
                    CmccDataStatistics.onEvent(HospitalActivity.this, 0,
                        "f_doc");
                    httpMap.put(Arguments.ACTIVITY_JUMP_SCREENING_TYPE, 2);
                    break;
                }
                PotoalParcelable potoal = new PotoalParcelable(httpMap);
                intent.putExtra(Arguments.INTENT_TO_NEXT_PAGE, potoal);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
            }
            else if (id == R.id.top_left_image)
            {
                Intent intent = new Intent(HospitalActivity.this,
                    NewIndexActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
                finish();
            }
            else if (id == R.id.top_search_btn)
            {
                three_head_layout.setVisibility(View.GONE);
                search_layout.setVisibility(View.VISIBLE);
            }
            else if (id == R.id.search_btn)
            {
                sendGetHospitalListTask("0", ConfigUtilHelper.getMobile(app),
                    search_edittext.getText().toString(), "", "1",
                    HttpAsyncTask.CACHE_TYPE_SAVE);
            }
            else
            {
                check(v.getId(), true);
            }
        }
    };

    /**
     * 
     * @param id
     * @param hasAnimation 是否需要动画
     */
    public void check(int id, boolean hasAnimation)
    {
        if (currentTitleSelect == id)
        {
            return;
        }
        if (currentTitleSelect > 0)
        {
            findViewById(currentTitleSelect).setSelected(false);
        }
        currentTitleSelect = id;
        findViewById(currentTitleSelect).setSelected(true);
        if (hasAnimation)
        {
            start3DAnimation(listView);
        }
        else
        {

        }
        listView.setVisibility(View.VISIBLE);
        no_data_layout.setVisibility(View.GONE);
    }

    @Override
    public void animFrushView()
    {
        switch (currentTitleSelect)
        {
        case R.id.left_btn:
            top_left.setBackgroundResource(R.drawable.by_hospital_press);
            top_center.setBackgroundResource(R.drawable.by_dept);
            top_right.setBackgroundResource(R.drawable.by_all_doctor);
            top_search_btn.setVisibility(View.VISIBLE);
            if (hospitalAdapter != null)
            {
                if (hospitalList.size() > 0)
                {
                    listView.setAdapter(hospitalAdapter);
                    showNoData(false);
                }
                else
                {
                    showNoData(true);
                }
            }
            else
            {
                listView.setAdapter(null);
                sendGetHospitalListTask("0", ConfigUtilHelper.getMobile(app),
                    "", "", "1", HttpAsyncTask.CACHE_TYPE_SAVE);
            }
            break;
        case R.id.center_btn:
            top_search_btn.setVisibility(View.GONE);
            top_left.setBackgroundResource(R.drawable.by_hospital);
            top_center.setBackgroundResource(R.drawable.by_dept_press);
            top_right.setBackgroundResource(R.drawable.by_all_doctor);
            if (departmentAdapter != null)
            {
                if (departmentList.size() > 0)
                {
                    listView.setAdapter(departmentAdapter);
                    showNoData(false);
                }
                else
                {
                    showNoData(true);
                }
            }
            else
            {
                listView.setAdapter(null);
                sendGetDepartmentListTask("0", ConfigUtilHelper.getMobile(app),
                    "", "", "1", HttpAsyncTask.CACHE_TYPE_SAVE);
            }
            break;
        case R.id.right_btn:
            top_search_btn.setVisibility(View.GONE);
            top_left.setBackgroundResource(R.drawable.by_hospital);
            top_center.setBackgroundResource(R.drawable.by_dept);
            top_right.setBackgroundResource(R.drawable.by_all_doctor_press);
            if (doctorAdapter != null)
            {
                if (doctorList.size() > 0)
                {
                    listView.setAdapter(doctorAdapter);
                    showNoData(false);
                }
                else
                {
                    showNoData(true);
                }
            }
            else
            {
                listView.setAdapter(null);
                sendGetDoctorListTask("0", ConfigUtilHelper.getMobile(app), "",
                    "", "", "1", HttpAsyncTask.CACHE_TYPE_SAVE);
            }
            break;
        }
    }

    Handler handler = new Handler() {

        @Override
        public void handleMessage(Message msg)
        {
            switch (currentTitleSelect)
            {
            case R.id.left_btn:
                sendGetHospitalListTask("0", ConfigUtilHelper.getMobile(app),
                    search_edittext.getText().toString(), "",
                    currPage + 1 + "", HttpAsyncTask.CACHE_TYPE_ACTION);
                break;
            case R.id.center_btn:
                sendGetDepartmentListTask("0", ConfigUtilHelper.getMobile(app),
                    "", "", currPage + 1 + "", HttpAsyncTask.CACHE_TYPE_ACTION);
                break;
            case R.id.right_btn:
                sendGetDoctorListTask("0", ConfigUtilHelper.getMobile(app), "",
                    "", "", currPage + 1 + "", HttpAsyncTask.CACHE_TYPE_ACTION);
                break;
            }
        }
    };

    /**
     * 是否显示无数据图片
     * 
     * @param flag
     */
    public void showNoData(boolean flag)
    {
        if (flag)
        {
            listView.setVisibility(View.GONE);
            no_data_layout.setVisibility(View.VISIBLE);
        }
        else
        {
            listView.setVisibility(View.VISIBLE);
            no_data_layout.setVisibility(View.GONE);
        }
    }

    public void setView()
    {
        switch (currentTitleSelect)
        {
        case R.id.left_btn:
            if (hospitalList.size() > 0)
            {
                if (hospitalAdapter == null)
                {
                    hospitalAdapter = new HospitalAdapter(context,
                        hospitalList, handler, currPage, allPage, false);
                    listView.setAdapter(hospitalAdapter);
                }
                else
                {
                    hospitalAdapter.list = hospitalList;
                    hospitalAdapter.currPage = currPage;
                    hospitalAdapter.allPage = allPage;
                    hospitalAdapter.notifyDataSetChanged();
                }
                showNoData(false);
            }
            else
            {
                showNoData(true);
            }
            break;
        case R.id.center_btn:
            if (departmentList.size() > 0)
            {
                if (departmentAdapter == null)
                {
                    departmentAdapter = new DepartmentAdapter(context,
                        departmentList, handler, currPage, allPage, false);
                    listView.setAdapter(departmentAdapter);
                }
                else
                {
                    departmentAdapter.list = departmentList;
                    departmentAdapter.currPage = currPage;
                    departmentAdapter.allPage = allPage;
                    departmentAdapter.notifyDataSetChanged();
                }
                showNoData(false);
            }
            else
            {
                showNoData(true);
            }
            break;
        case R.id.right_btn:
            if (doctorList.size() > 0)
            {
                if (doctorAdapter == null)
                {
                    doctorAdapter = new DoctorAdapter(context, doctorList,
                        handler, currPage, allPage, false);
                    listView.setAdapter(doctorAdapter);
                }
                else
                {
                    doctorAdapter.list = doctorList;
                    doctorAdapter.currPage = currPage;
                    doctorAdapter.allPage = allPage;
                    doctorAdapter.notifyDataSetChanged();
                }
                showNoData(false);
            }
            else
            {
                showNoData(true);
            }
            break;
        }
    }

    /**
     * 获取医院列表
     */
    private HttpAsyncTask sendGetHospitalListTask;

    /**
     * 
     * @param area_type 区域类别 0：本地 1：异地 2 所有
     * @param mobile 手机号码 如果为空，则不处理关注相关数据
     * @param is_attention 是否已关注 缺省时查询全部，1只返回已关注数据
     * @param page 页数 0 表示不分页为所有，分页从1开始
     * @param pageSize 每页记录数 默认为10
     */
    protected void sendGetHospitalListTask(String area_type, String mobile,
        String search_content, String is_attention, String page, int cacheType)
    {
        logger.d("----------sendGetHospitalListTask----------");
        Map<String, String> parameterMap = new HashMap<String, String>();
        parameterMap.put("area_type", area_type);
        parameterMap.put("mobile", mobile);
        parameterMap.put("is_attention", is_attention);
        parameterMap.put("page", page);
        parameterMap.put("search_content", search_content);
        parameterMap.put("pageSize", Arguments.pageSize);
        String getHospitalListUrl = Utils.changeUrl(
            Arguments.SERVER_URL_GET_HOSPITAL_LIST, parameterMap);
        if (ConfigUtilHelper.debug)
        {
            Log.i(TAG, "获取医院列表：" + getHospitalListUrl);
        }
        if (cacheType == HttpAsyncTask.CACHE_TYPE_ACTION)
        {
            sendGetHospitalListTask = new HttpAsyncTask(HttpAsyncTask.GET,
                GlobalSetting.XML_HOSPITAL_LIST, getHospitalListUrl, cacheType,
                true);
        }
        else
        {
            sendGetHospitalListTask = new HttpAsyncTask(HttpAsyncTask.GET,
                GlobalSetting.XML_HOSPITAL_LIST, getHospitalListUrl, cacheType,
                false);
        }
        sendGetHospitalListTask.setUIHandler(sendGetHospitalListHandler);
        mHttpManager.execute(sendGetHospitalListTask);
    }

    @SuppressWarnings("unchecked")
    Handler sendGetHospitalListHandler = new Handler() {
        public void handleMessage(Message msg)
        {
            logger.d("----------sendGetHospitalListHandler----------");
            switch (msg.what)
            {
            case HttpAsyncTask.TASK_NOTIFY_RETURN_DATA:
                dismissProgressDialog();
                if (msg.obj != null)
                {
                    try
                    {
                        Map<String, Object> httpMap = (Map<String, Object>) msg.obj;
                        List<Hospital> hospital_1 = (List<Hospital>) httpMap
                            .get(Arguments.XML_HOSPITAL_LIST);
                        allPage = Integer.parseInt((String) httpMap
                            .get(Arguments.XML_ALLPAGE));
                        currPage = Integer.parseInt((String) httpMap
                            .get(Arguments.XML_CURRPAGE));
                        if (currPage == 1)
                        {
                            hospitalList = hospital_1;
                        }
                        else
                        {
                            hospitalList.addAll(hospital_1);
                        }
                    }
                    catch (Exception e)
                    {
                        e.printStackTrace();
                        allPage = currPage;
                    }
                }
                else
                {
                    showNoData(true);
                    return;
                }
                setView();
                break;
            case HttpAsyncTask.TASK_NOTIFY_CONNECTION_FAIL:
                dismissProgressDialog();
                showSingleAlertDlg(getString(R.string.notice),
                    getString(R.string.read_fail), getString(R.string.close));

                allPage = currPage;
                setView();
                break;
            }
        }
    };

    /**
     * 获取科室列表
     */
    private HttpAsyncTask sendGetDepartmentListTask;

    /**
     * 
     * @param area_type 区域类别 0：本地 1：异地 2 所有
     * @param mobile 手机号码 如果为空，则不处理关注相关数据
     * @param unit_id 医院id 如果为空，获取所有的科室， 如果不为空，获取所在医院的科室
     * @param is_attention 是否已关注 缺省时查询全部，1只返回已关注数据
     * @param page 页数 0 表示不分页为所有，分页从1开始
     * @param pageSize 每页记录数 默认为10
     */
    protected void sendGetDepartmentListTask(String area_type, String mobile,
        String unit_id, String is_attention, String page, int cache_type)
    {
        logger.d("----------sendGetDepartmentListTask----------" + page);
        Map<String, String> parameterMap = new HashMap<String, String>();
        parameterMap.put("area_type", area_type);
        parameterMap.put("mobile", mobile);
        parameterMap.put("unit_id", unit_id);
        parameterMap.put("is_attention", is_attention);
        parameterMap.put("page", page);
        parameterMap.put("pageSize", Arguments.pageSize);
        parameterMap.put("dep_level", "1");// 获取重点科室
        String getDepartmentListUrl = Utils.changeUrl(
            Arguments.SERVER_URL_GET_DEPARTMENT_LIST, parameterMap);
        if (ConfigUtilHelper.debug)
        {
            Log.i(TAG, "获取科室列表：" + getDepartmentListUrl);
        }
        if (cache_type == HttpAsyncTask.CACHE_TYPE_ACTION)
        {
            sendGetDepartmentListTask = new HttpAsyncTask(HttpAsyncTask.GET,
                GlobalSetting.XML_DEPARTMENT_LIST, getDepartmentListUrl,
                cache_type, true);
        }
        else
        {
            sendGetDepartmentListTask = new HttpAsyncTask(HttpAsyncTask.GET,
                GlobalSetting.XML_DEPARTMENT_LIST, getDepartmentListUrl,
                cache_type, false);
        }
        sendGetDepartmentListTask
            .setUIHandler(sendGetDepartmentListTaskHandler);
        mHttpManager.execute(sendGetDepartmentListTask);
    }

    @SuppressWarnings("unchecked")
    Handler sendGetDepartmentListTaskHandler = new Handler() {
        public void handleMessage(Message msg)
        {
            logger.d("----------sendGetDepartmentListTaskHandler----------");
            switch (msg.what)
            {
            case HttpAsyncTask.TASK_NOTIFY_RETURN_DATA:
                dismissProgressDialog();
                if (msg.obj != null)
                {
                    Map<String, Object> httpMap = (Map<String, Object>) msg.obj;
                    try
                    {
                        allPage = Integer.parseInt((String) httpMap
                            .get(Arguments.XML_ALLPAGE));
                        currPage = Integer.parseInt((String) httpMap
                            .get(Arguments.XML_CURRPAGE));
                        List<Department> departmentList_1 = (List<Department>) httpMap
                            .get(Arguments.XML_DEPARTMENT_LIST);
                        if (currPage == 1)
                        {
                            departmentList = departmentList_1;
                        }
                        else
                        {
                            departmentList.addAll(departmentList_1);
                        }
                    }
                    catch (Exception e)
                    {
                        e.printStackTrace();
                        allPage = currPage;
                    }
                }
                setView();
                break;
            case HttpAsyncTask.TASK_NOTIFY_CONNECTION_FAIL:
                dismissProgressDialog();
                showSingleAlertDlg(getString(R.string.notice),
                    getString(R.string.read_fail), getString(R.string.close));
                allPage = currPage;
                setView();
                break;
            }
        }
    };

    /**
     * 获取医生列表
     */
    private HttpAsyncTask sendGetDoctorListTask;

    /**
     * 
     * @param area_type 区域类别 0：本地 1：异地 2 所有
     * @param mobile 手机号码 如果为空，则不处理关注相关数据
     * @param unit_id 医院id 如果为空，获取所有的科室， 如果不为空，获取所在医院的科室
     * @param dep_id 科室id 如果为空，获取所有的医生， 如果不为空，获取所在科室的医生
     * @param is_attention 是否已关注 缺省时查询全部，1只返回已关注数据
     * @param page 页数 0 表示不分页为所有，分页从1开始
     * @param pageSize 每页记录数 默认为10
     */
    protected void sendGetDoctorListTask(String area_type, String mobile,
        String unit_id, String dep_id, String is_attention, String page,
        int cache_type)
    {
        logger.d("----------sendGetDoctorListTask----------");
        Map<String, String> parameterMap = new HashMap<String, String>();
        parameterMap.put("area_type", area_type);
        parameterMap.put("mobile", mobile);
        parameterMap.put("unit_id", unit_id);
        parameterMap.put("dep_id", dep_id);
        parameterMap.put("is_attention", is_attention);
        parameterMap.put("page", page);
        parameterMap.put("pageSize", Arguments.pageSize);
        String getDoctorListUrl = Utils.changeUrl(
            Arguments.SERVER_URL_GET_DOCTOR_LIST, parameterMap);
        if (ConfigUtilHelper.debug)
        {
            Log.i(TAG, "获取医生列表：" + getDoctorListUrl);
        }
        if (cache_type == HttpAsyncTask.CACHE_TYPE_ACTION)
        {
            sendGetDoctorListTask = new HttpAsyncTask(HttpAsyncTask.GET,
                GlobalSetting.XML_DOCTOR_LIST, getDoctorListUrl, cache_type,
                true);
        }
        else
        {
            sendGetDoctorListTask = new HttpAsyncTask(HttpAsyncTask.GET,
                GlobalSetting.XML_DOCTOR_LIST, getDoctorListUrl, cache_type,
                false);
        }
        sendGetDoctorListTask.setUIHandler(sendGetDoctorListTaskHandler);
        mHttpManager.execute(sendGetDoctorListTask);
    }

    @SuppressWarnings("unchecked")
    Handler sendGetDoctorListTaskHandler = new Handler() {
        public void handleMessage(Message msg)
        {
            logger.d("----------sendGetDoctorListTaskHandler----------");
            switch (msg.what)
            {
            case HttpAsyncTask.TASK_NOTIFY_RETURN_DATA:
                dismissProgressDialog();
                if (msg.obj != null)
                {
                    try
                    {
                        Map<String, Object> httpMap = (Map<String, Object>) msg.obj;
                        allPage = Integer.parseInt((String) httpMap
                            .get(Arguments.XML_ALLPAGE));
                        currPage = Integer.parseInt((String) httpMap
                            .get(Arguments.XML_CURRPAGE));
                        List<Doctor> doctorList_1 = (List<Doctor>) httpMap
                            .get(Arguments.XML_DOCTOR_LIST);
                        if (currPage == 1)
                        {
                            doctorList = doctorList_1;
                        }
                        else
                        {
                            doctorList.addAll(doctorList_1);
                        }
                    }
                    catch (Exception e)
                    {
                        e.printStackTrace();
                        allPage = currPage;
                    }
                }
                setView();
                break;
            case HttpAsyncTask.TASK_NOTIFY_CONNECTION_FAIL:
                dismissProgressDialog();
                showSingleAlertDlg(getString(R.string.notice),
                    getString(R.string.read_fail), getString(R.string.close));
                allPage = currPage;
                setView();
                break;
            }
        }
    };

    @Override
    protected void setTaskHandlerNull()
    {
        if (sendGetHospitalListTask != null)
        {
            sendGetHospitalListTask.setTaskBindingHandler(null);
        }
        if (sendGetDepartmentListTask != null)
        {
            sendGetDepartmentListTask.setTaskBindingHandler(null);
        }
        if (sendGetDoctorListTask != null)
        {
            sendGetDoctorListTask.setTaskBindingHandler(null);
        }
    }

    @Override
    protected void onResume()
    {
        super.onResume();
        if (app.changeAttention)
        {
            switch (app.type)
            {
            case 0:
                if (hospitalAdapter != null)
                {
                    Hospital hospital = hospitalList.get(app.position);
                    hospital.is_attention = app.attentioin;
                    hospitalList.set(app.position, hospital);
                    hospitalAdapter.list = hospitalList;
                    hospitalAdapter.notifyDataSetChanged();
                }
                break;
            case 1:
                if (departmentAdapter != null)
                {
                    Department department = departmentList.get(app.position);
                    department.is_attention = app.attentioin;
                    departmentList.set(app.position, department);
                    departmentAdapter.list = departmentList;
                    departmentAdapter.notifyDataSetChanged();
                }
                break;
            case 2:
                if (doctorAdapter != null)
                {
                    Doctor doctor = doctorList.get(app.position);
                    doctor.is_attention = app.attentioin;
                    doctorList.set(app.position, doctor);
                    doctorAdapter.list = doctorList;
                    doctorAdapter.notifyDataSetChanged();
                }
                break;
            }
            app.changeAttention = false;
            app.position = -1;
            app.type = -1;
            app.attentioin = "";
        }
    }

}